<template>
	<view class="center">
		
	</view>
</template>

<script>
	import service_player from '@/service/player.js';
	export default {
		data() {
			return {
				user_id: uni.getStorageSync('userId'),
				id: '',
				back: false,
			}
		},
		onLoad(options) {
			this.id = options.room_id;
			uni.setStorageSync('query', options.custom_params)
			console.log(this.id, 'onLoad-paly')
			let token = uni.getStorageSync('token')
			uni.setStorageSync('roomId', options.room_id)
			
			if (token=='' || token==null) {
				uni.setStorageSync('Router', 'pages/livePlayer/index/index?id=' + options.room_id)
				uni.redirectTo({
					url: '/pages_login/pages/login/login/index'
				});
			} else {
				//this.xcxLivePlayer(options.room_id, options.custom_params);
			}
		},
		onShow() {
			if (this.back === true) {
				this.back = false;
				uni.switchTab({
					url: '/pages/home/index/index'
				});
				return false;
			} else {
				var _this=this;
				let token = uni.getStorageSync('token')
				let room_id = uni.getStorageSync('roomId')
				let query = uni.getStorageSync('query')
				setTimeout(function() {
					if (token!='' && room_id != '') {
						//_this.xcxLivePlayer(room_id,query);
					}
				}, 1500)
			}
		},
		methods: {
			//直播分享
			xcxLivePlayer(ids,custom_param) {
				//小程序进直播间
				var roomId = [ids] // 房间号
				var customParams = encodeURIComponent(JSON.stringify({
					path: 'pages/livePlayer/index/index',
					userId: this.user_id
				}))
				var _this = this;
				setTimeout(function() {
					_this.back = true;
				}, 1500);
				// var custom_decode = decodeURIComponent(custom_param);
				// let custom_params = JSON.parse(custom_decode.custom_params);
				let share_uid =custom_param;
				uni.showModal({
				    title: '提示',
				    content: share_uid+'分享者+房间号'+ids,
					showCancel:false,
				    success: function (res) {
				      
				    }
				});
				if (share_uid > 0 && share_uid != '') {
					let params = {
						invit_user_id: share_uid,
						roomid: ids
					};
					service_player.xcxLiveShare(params).then(res => {
						uni.showModal({
						    title: '提示',
						    content:res+'分享成功',
							showCancel:false,
						    success: function (res) {
						      
						    }
						});
						//uni.removeStorageSync('liveShare');
						uni.removeStorageSync('roomId');
						uni.navigateTo({
							url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${custom_param}`
						});
					})
				} else {
					uni.showModal({
					    title: '提示',
					    content:'直接进直播间',
						showCancel:false,
					    success: function (res) {
					      
					    }
					});
					uni.removeStorageSync('roomId');
					uni.navigateTo({
						url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${custom_param}`
					});
				}
			}
		},
	}
</script>

<style>
</style>
